package ca.cbc.localsrvextadmin.converter;

import java.util.Date;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import ca.cbc.giscommon.dao.CategoryDAO;
import ca.cbc.giscommon.entity.Category;


public class CategoryConverter extends StrutsTypeConverter {

	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		Category c = null;
        if (values != null && values.length > 0 && values[0] != null && values[0].length() > 0) {
        	String id = values[0];
        	c = new CategoryDAO().findById(Long.valueOf(id));
        }
		return c;
	}

	@Override
	public String convertToString(Map context, Object o) {
		if (o instanceof Category) {
			return ((Category) o).getName();
		}
		return null;
	}

}
